#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QMessageBox* message = new QMessageBox(this);
    message->setWindowTitle("对话框标题");
    message->setText("这是一个对话框");
    message->setIcon(QMessageBox::Warning);
    message->setStandardButtons(QMessageBox::Ok | QMessageBox::Save | QMessageBox::Close);

//    // 自定义按钮
//    QPushButton* pushbutton = new QPushButton("按钮",message);
//    message->addButton(pushbutton,QMessageBox::AcceptRole);


    // 模态，模态情况下，除非对话框被手动关闭，否则会阻塞在此
    int result = message->exec();
    if(result == QMessageBox::Ok)
        qDebug() << "OK";
    else if(result == QMessageBox::Save)
        qDebug() << "Save";
    else if(result == QMessageBox::Close)
        qDebug() << "Close";
    message->setAttribute(Qt::WA_DeleteOnClose);
}
